package com.fattyCorps.controller;

import com.fattyCorps.an.AMsgType;
import com.fattyCorps.obj.db.Hero;
import com.fattyCorps.obj.msg.SRet;
import com.fattyCorps.obj.msg.client.hero.CCreateHeroMsg;
import com.fattyCorps.obj.msg.client.hero.CHeroLvUpMsg;
import com.fattyCorps.obj.msg.client.hero.CHeroStarUpMsg;
import com.fattyCorps.obj.msg.client.item.CUseItemMsg;
import com.fattyCorps.service.HeroService;
import com.fattyCorps.service.ItemService;
import com.fattyCorps.utils.ServletUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/item")
public class ItemController {

    @Autowired
    ItemService itemService;
//
//    @PostMapping("/create")
//    public SRet create(HttpServletRequest request, @RequestBody CCreateHeroMsg cCreateHeroMsg) {
//        Integer playerId = ServletUtils.getPlayerIdByRequest(request);
//        heroService.createHero(playerId, cCreateHeroMsg.getHeroTypeId());
//        return SRet.success();
//    }

    @PostMapping("/getItemList")
    @AMsgType(readOnly = true)
    public SRet getItemList(HttpServletRequest request) {
        Integer playerId = ServletUtils.getPlayerIdByRequest(request);
        SRet itemList = itemService.getItemList(playerId);
        return itemList;
    }

    @PostMapping("/useItem")
    public SRet useItem(HttpServletRequest request, @RequestBody CUseItemMsg cUseItemMsg) {
        Integer playerId = ServletUtils.getPlayerIdByRequest(request);
        SRet sRet = itemService.useItem(playerId, cUseItemMsg.getItemId(), cUseItemMsg.getNum());
        return SRet.success();
    }
}
